/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package masters.servlet.ventas;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import masters.dao.VentasDAO;
import masters.excepcion.DAOExcepcion;
import masters.modelo.Ventas;

/**
 * Servlet implementation class for Servlet: UsuarioInsertarServlet
 *
 */
public class VentasInsertarServlet extends javax.servlet.http.HttpServlet
		implements javax.servlet.Servlet {
	static final long serialVersionUID = 1L;

	/*
	 * (non-Java-doc)
	 *
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public VentasInsertarServlet() {
		super();
	}

	/*
	 * (non-Java-doc)
	 *
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/*
	 * (non-Java-doc)
	 *
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		//
		String a = request.getParameter("idVentas");
                int aa = Integer.valueOf(a);
                String b = request.getParameter("Producto_idProducto");
                int bb = Integer.valueOf(b);
		String c = request.getParameter("cantidad");
		String d = request.getParameter("precio_unidad");
		String e = request.getParameter("precio_total");




		Ventas vo = new Ventas();
                vo.setIdventas(aa);
		vo.setIdproducto(bb);
		vo.setCantidad(c);
		vo.setPrecio_unidad(d);
		vo.setPrecio_total(e);


		VentasDAO dao = new VentasDAO();
		try {
			dao.insertar(vo);
			RequestDispatcher rd = request
					.getRequestDispatcher("/adminventas.jsp");
			rd.forward(request, response);
		} catch (DAOExcepcion e1) {
			System.err.println("Error");
			RequestDispatcher rd = request.getRequestDispatcher("/error.jsp");
			rd.forward(request, response);
		}

	}
}
